package com.ruoyi.web.controller.mongo;

import com.ruoyi.mongo.cet4.service.ComprehensiveInterface;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.mongo.comprehensive.ExamData;
import com.ruoyi.mongo.comprehensive.ExamRecord;
import com.ruoyi.mongo.comprehensive.ReadingAnswer;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController()
@RequestMapping("/comprehensive")
public class ComprehensiveController extends BaseController {

    private final ComprehensiveInterface comprehensiveInterface;

    public ComprehensiveController(ComprehensiveInterface comprehensiveInterface) {
        this.comprehensiveInterface = comprehensiveInterface;
    }

    @PostMapping("/exam")
    public AjaxResult postUserInputDataExam(@RequestBody ExamData examData) {
        boolean insertedExamData = comprehensiveInterface.insertExamData(examData);
        return AjaxResult.success(insertedExamData);
    }

    @GetMapping("/list")
    public AjaxResult getExamList(@RequestParam(required = false) ExamData examData) {
        List<ExamRecord> list = comprehensiveInterface.selectExamDataList(examData);
        return AjaxResult.success(list);
    }

    @GetMapping("/query")
    public AjaxResult getExamRecordList(@ModelAttribute("queryData") ExamData examData) {
        List<ExamRecord> list = comprehensiveInterface.selectQueryRecordList(examData);
        return AjaxResult.success(list);
    }

    @GetMapping("/page")
    public TableDataInfo getExamRecordPageList(@ModelAttribute("queryData") ExamData examData) {
        startPage();
        List<ExamRecord> list = comprehensiveInterface.selectQueryRecordList(examData);
        return getDataTable(list);
    }

    @GetMapping("/detail/{id}")
    public AjaxResult getExamRecordDetail(@PathVariable String id) {
        List<ReadingAnswer> list = comprehensiveInterface.selectQueryRecordDetail(id);
        return AjaxResult.success(list);
    }
}
